local PayMgr = class("PayMgr");
function PayMgr:ctor()
    
end

function PayMgr:pay(paytype,sign)
    if paytype == 1 then
        self:aliPay(sign)
    end
end

function PayMgr:aliPay(sign)
    local ok = nil
    local ret = nil
    if device.platform == "windows" then
        mgrs.log:printDebug("PayMgr:aliPay windows")
    elseif device.platform == "android" then
        local function aliPayCallBack(ret)
            self:payResult(ret)
        end
        local args = {sign,aliPayCallBack}
        local sig = "(Ljava/lang/String;I)Z"
        local AliPayClass = "org/cocos2dx/lua/AppActivity"
        ok, ret = luaj.callStaticMethod(AliPayClass, "payAli", args,sig) --没有返回默认nil
    elseif device.platform == "ios" then
        local function aliPayCallBack(ret)
            self:payResult(ret)
        end
        local args = {sign = sign,listener = aliPayCallBack}
        local ocfilenam = "AliHelper"
        local ocfuncname = "aliPayItem"
        ok, ret = luaoc.callStaticMethod(ocfilenam, ocfuncname, args)
    end
    print(ok,ret)
end



function PayMgr:payResult(ret)
    if type(ret) ~= "number" then
        return
    end
    if ret == enums.PayResult.PAY_SUCESS then
        print("sucess")
    elseif ret == enums.PayResult.PAY_FAILED then
        print("failed")
    elseif ret == enums.PayResult.PAY_CANCLE then
        print("cancle")
    elseif ret == enums.PayResult.PAY_NET_ERROR then  
        print("net work error")
    elseif ret == enums.PayResult.PAY_WAIT then  
        print("wait")
    end
end


mgrs.pay = nil;
mgrs.singleClass(mgrs,PayMgr,"pay");